package com.module.content.utils

import java.util.*

/**
 * author : Allen
 * date   : 2020/08/29
 * time   : 11:31
 * desc   :
 */
object InfoUtils {
    fun getDuration(timeMs: Int): String {
        if (timeMs <= 0 || timeMs >= 24 * 60 * 60 * 1000) {
            return "0:00"
        }
        val totalSeconds: Int = timeMs / 1000
        val seconds = totalSeconds % 60
        val minutes = totalSeconds / 60 % 60
        val hours = totalSeconds / 3600
        val stringBuilder = StringBuilder()
        val mFormatter =
            Formatter(stringBuilder, Locale.getDefault())
        return if (hours > 0) {
            mFormatter.format("%d:%02d:%02d", hours, minutes, seconds).toString()
        } else {
            mFormatter.format("%2d:%02d", minutes, seconds).toString()
        }
    }
}